#!/usr/bin/env Python
# coding=utf-8


import handlers.base as baseHandler
import methods.database.orm.login_user as login_user
import json
class UserHandler(baseHandler.BaseHandler):
    def get(self):
        self.post()
    def post(self):
        username = self.get_argument("user")
        self.render("login/user.html", users=username)

class RegisterHandler(baseHandler.BaseHandler):
    def post(self):
        data = json.loads(self.request.body)
        login_name = data["username"]
        password = data["password"]
        data = {"login_name": login_name}
        user_infos = login_user.getUser(data)
        if user_infos:
            self.write({"status": 2, "msg": "该用户名已被注册"})
        else:
            data = {"login_name": login_name, "password": password}
            user_infos = login_user.addUser(data)
            if user_infos:
                self.write({"status": 0, "msg": "注册成功"})
            else:
                self.write({"status": 1, "msg": "注册失败"})